package com.github.wangmingchang.sqltransformbean.enums;

import org.apache.ibatis.type.JdbcType;

/**
 *  MySql、Mybatis、java三都类型的映射关系
 * @author wangmingchang
 * @date 2020/8/25 09:00
 */
public enum MysqlTypeEnum {

    CHAR("CHAR", "CHAR", "String"),
    VARCHAR("VARCHAR", "VARCHAR", "String"),
    LONGVARCHAR("VARCHAR", "LONGVARCHAR", "String"),
    TEXT("TEXT", "VARCHAR", "String"),
    LONGTEXT("LONGTEXT", "LONGVARCHAR", "String"),
    MEDIUMTEXT("MEDIUMTEXT", "MEDIUMTEXT", "String"),
    NUMERIC("NUMERIC", "NUMERIC", "java.math.BigDecimal"),
    DECIMAL("DECIMAL", "DECIMAL", "java.math.BigDecimal"),
    BIT("BIT", "BIT", "Boolean"),
    TINYINT("TINYINT", "TINYINT", "Byte"),
    SMALLINT("SMALLINT", "SMALLINT", "Short"),
    INTEGER("INTEGER", "INTEGER", "Integer"),
    INT("INT", "INTEGER", "Integer"),
    BIGINT("BIGINT", "BIGINT", "Long"),
    REAL("REAL", "REAL", "Float"),
    FLOAT("FLOAT", "FLOAT", "Double"),
    DOUBLE("DOUBLE", "DOUBLE", "Double"),
    DATE("DATE", "DATE", "java.util.Date"),
    DATETIME("DATETIME", "TIMESTAMP", "java.util.Date"),
    TIME("TIME", "TIME", "Time"),
    TIMESTAMP("TIMESTAMP", "TIMESTAMP", "java.util.Date"),
    CLOB("CLOB", "CLOB", "Clob"),
    BLOB("BLOB", "BLOB", "Blob"),

    ;


    private String mysqlType;
    private String mybatisType;
    private String javaType;


    public static MysqlTypeEnum match(String mysqlType){
        mysqlType = mysqlType.toUpperCase();
        MysqlTypeEnum[] values = MysqlTypeEnum.values();
        for (MysqlTypeEnum mysqlTypeEnum : values){
            if(mysqlTypeEnum.getMysqlType().equals(mysqlType)){
                return mysqlTypeEnum;
            }
        }
        return null;
    }

    MysqlTypeEnum(String mysqlType, String mybatisType, String javaType) {
        this.mysqlType = mysqlType;
        this.mybatisType = mybatisType;
        this.javaType = javaType;
    }

    public String getMysqlType() {
        return mysqlType;
    }

    public String getMybatisType() {
        return mybatisType;
    }

    public String getJavaType() {
        return javaType;
    }

    @Override
    public String toString() {
        return "MysqlTypeEnum{" +
                "mysqlType='" + mysqlType + '\'' +
                ", mybatisType='" + mybatisType + '\'' +
                ", javaType='" + javaType + '\'' +
                "} ";
    }
}
